#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Example script to run an immediate backup using the OSS Backup Tool
"""

import os
import sys
import logging
from oss_backup import OssBackupTool

def main():
    # Configure logging for this script
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(levelname)s - %(message)s',
        handlers=[
            logging.StreamHandler(sys.stdout)
        ]
    )
    logger = logging.getLogger(__name__)
    
    logger.info("Starting immediate backup...")
    
    # Create an instance of the backup tool
    backup_tool = OssBackupTool()
    
    # Run backup immediately
    success = backup_tool.run_backup()
    
    if success:
        logger.info("Backup completed successfully!")
    else:
        logger.error("Backup completed with errors. Check the log file for details.")
        
    # Optional: Clean up old backups
    if success and input("Do you want to clean up old backups? (y/n): ").lower() == 'y':
        backup_tool.cleanup_old_backups()
        logger.info("Old backups cleaned up according to retention policy")
    
    return 0 if success else 1

if __name__ == "__main__":
    sys.exit(main()) 